#ifndef _FUNCTIONLIST_H_
#define _FUNCTIONLIST_H_

#include "StringList.h"

typedef struct {
    int Version;
    short StringListOffset;
    short StringListCount;
    short FunctionListOffset;
    short FunctionListCount;
} PARSE_FILE_HEAD;

typedef struct {
    short Len;
    char String[1];
} PARSE_STRING_LIST;

typedef struct {
    short FunctionName;
    short FunctionLength;
    int FunctionOffset;
    int FunctionType;
} PARSE_FUNCTION_LIST;

#define PARSE_TYPE_RETURN_ITEM    0x01
#define PARSE_TYPE_RETURN_ADDR    0x02
#define PARSE_TYPE_RETURN_DEFAULE 0x03

class FunctionList
{
public:
	struct ListItem{
		int name;
		int size;
		char *bin;
		int type;
	};
	ListItem *items;
	int count;
	StringList strings;
private:
	unsigned char temp[1024];

public:
	FunctionList();
	virtual ~FunctionList();
	int add(const char *buf, int begin, int end);

private:
	static int findBegin(const char *buf, int begin, int end);
	static int findEnd(const char *buf, int begin, int end);
	static BufferString& readString(const char *buf, int &begin, int end);
	static int readLine(const char *buf, int &begin, int end);
	void add(int name, int size, int type);
	void addString(BufferString &str, int size);
	bool addLabel(unsigned char cmd, int &size, const char *buf, int len);
	void addCommand(BufferString cmd, int &size, const char *buf, int len);
};

#endif // _FUNCTIONLIST_H_
